package template

type iotp interface {
	genRandomOTP(int) string
	saveOTPCache(string)
	getMessage(string) string
	notify(string) error
	publishMetric()
}

type otp struct {
	iotp
}

func (o otp) genAndSendOTP(len int) error {
	otp := o.iotp.genRandomOTP(len)
	o.iotp.saveOTPCache(otp)
	message := o.iotp.getMessage(otp)
	err := o.iotp.notify(message)
	if err != nil {
		return err
	}
	o.iotp.publishMetric()
	return nil
}
